/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */
require('../bootstrap');

axios.defaults.baseURL = config.baseUrl;

window.Vue = require('vue');


/**
 * The following block of code may be used to automatically register your
 * Vue components. It will recursively scan this directory for the Vue
 * components and automatically register them with their "basename".
 *
 * Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
 */

// const files = require.context('./', true, /\.vue$/i);
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));

// Vue.component('example-component', require('../components/ExampleComponent.vue').default);

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

import ElementUI from 'element-ui';
import VueRouter from 'vue-router';

import TreeNavMenu from './components/TreeNavMenu';
import UserIndex from "./views/UserIndex";
// import UserShow from "./views/UserShow";
import CareerIndex from "./views/CareerIndex";
import CareerCreate from "./views/CareerCreate";
import CareerEdit from "./views/CareerEdit";
import SkillIndex from "./views/SkillIndex";
import SkillEdit from "./views/SkillEdit";
import CourseIndex from "./views/CourseIndex";
import CourseCreate from "./views/CourseCreate";
import CourserEdit from "./views/CourseEdit";
import WorkIndex from "./views/WorkIndex";
import WorkCreate from "./views/WorkCreate";
import WorkEdit from "./views/WorkEdit";
import UserWorkIndex from "./views/UserWorkIndex";
const routes = [
    {path: '/users', name: 'user-index', component: UserIndex},
    // {path: '/users/:user', name: 'user-show', component: UserShow},
    {path: '/careers', name: 'career-index', component: CareerIndex},
    {path: '/careers/create', name: 'career-create', component: CareerCreate},
    {path: '/careers/:career/edit', name: 'career-edit', component: CareerEdit},
    {path: '/skills', name: 'skill-index', component: SkillIndex},
    {path: '/skills/:skill/edit', name: 'skill-edit', component: SkillEdit},
    {path: '/courses', name: 'course-index', component: CourseIndex},
    {path: '/courses/create', name: 'course-create', component: CourseCreate},
    {path: '/courses/:course/edit', name: 'course-edit', component: CourserEdit},
    {path: '/courses/:course/works', name: 'work-index', component: WorkIndex},
    {path: '/courses/:course/works/create', name: 'work-create', component: WorkCreate},
    {path: '/works/:work/edit', name: 'work-edit', component: WorkEdit},
    {path: '/user-work', name: 'user-work-index', component: UserWorkIndex},
];


const router = new VueRouter({
    routes
});

Vue.use(VueRouter);
Vue.use(ElementUI);
import VueQuillEditor, {Quill} from 'vue-quill-editor'

import {ImageDrop} from 'quill-image-drop-module';

Quill.register('modules/imageDrop', ImageDrop);

// import  {ImageResize}  from 'quill-image-resize-module';
// Quill.register('modules/imageResize', ImageResize);

Vue.use(VueQuillEditor,)

Vue.component('tree-nav-menu', TreeNavMenu);

const dashboard = new Vue({
    router,
    el: '#app',

});

axios.interceptors.response.use(function (response) {
    return response;
}, function (error) {
    switch (error.response.status) {
        case 429:
            dashboard.$message.error('操作太快了');
            break;
        case 419:
            dashboard.$alert('CSRF令牌已过期，请刷新页面');
            break;
        case 403:
            dashboard.$message.error('您无权限操作');
            break;
        default:
            dashboard.$message.error(error.response.data.message);
    }
    return Promise.reject(error);
});